
void onTimer(Timer_win* self);

class Clock : public Form
{
  public:
  
  Timer_win* timer;

  void init(){
    Form::init("time");
    id = 123;
    height = 60;
    width = 220;
    pos_x = 1024 - width - 10;
    pos_y = 768 - height - 10;
    color = getRGB565(0x00FF0000);
    regDraw(Clock::draw);
    {
      timer = new Timer_win();
      timer->interval = 1000;//ms
      timer->nextTick = 0;//ms
      timer->pOnTime = onTimer;
      ::windows->addTimer(timer);
    }
  }

  static void draw(Form* form){
    FILE* s = form->getStream(5, 22, 200, 200);
    char datetime[8];
    //0 sec
    //1 min
    //2 hr
    //3 date
    //4 month
    //5 week
    //6 year
    //7 wp
    getTime(datetime);
    
    //if(datetime[7] & 0x80){
    //  datetime[7] = 0;
    //  datetime[6] = 1;
    //  datetime[5] = 1;
    //  datetime[4] = 1;
    //  datetime[3] = 1;
    //  datetime[2] = 0;
    //  datetime[1] = 0;
    //  datetime[0] = 0;
    //  setTime(datetime);
    //}

    
    fprintf(s, "wp,ww yy/MM/dd HH:mm:ss\r\n");
    fprintf(s, "%02X,%02X %02X/%02X/%02X %02X:%02X:%02X",datetime[7] & 0xFF, datetime[5] & 0xFF, datetime[6] & 0xFF, datetime[4] & 0xFF, datetime[3] & 0xFF, datetime[2] & 0xFF, datetime[1] & 0xFF, datetime[0] & 0xFF);

  }

};


void onTimer(Timer_win* self){
  ((Window*)clock)->draw();
}
